package cc.yiueil.ceate;

/**
 * CreateThread1 创建线程的方式1
 * 继承 Thread 类, 重写run()方法
 *
 * @version 1.0
 */
public class CreateThread2 {
    public static void main(String[] args) {
        System.out.println("start main thread!");
        Thread thread1 = new Thread(new CustomRunnable());
        Thread thread2 = new Thread(() -> {
            System.out.println("start new thread!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("end new thread!");
        });
        // 启动新线程
        thread1.start();
        thread2.start();
        System.out.println("end main thread!");
    }
}

class CustomRunnable implements Runnable {
    @Override
    public void run() {
        System.out.println("start new thread!");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("end new thread!");
    }
}
